import axios from 'axios'
import React, { PureComponent } from 'react'

// import { connect } from '../utils/connect'
import { connect } from 'react-redux'

import { addAction, changeRecommendsAction,changeBannersAction } from '../store/actionCreators'

class Home extends PureComponent {
  componentDidMount() {
    axios({
      url: "http://123.207.32.32:8000/home/multidata",
    }).then(res => {
      const data = res.data.data;
      console.log(data.recommend.list);
      this.props.changeBanners(data.banner.list);
      this.props.changeRecommend(data.recommend.list);
      console.log();
    })
  }
  render() {
    return (
      <div>
        <h1>Home</h1>
        <h2>当前计数：{this.props.counter}</h2>
        <button onClick={e => this.props.increment()}>+1</button>
        <button onClick={e => this.props.addNumber(6)}>+6</button>
      </div>
    )
  }
}

const mapStateToProps = state => {
  return {
    counter: state.counter
  }
};
const mapDispachToProp = dispatch => {
  return {
    increment: function () {
      dispatch(addAction(1))
    },
    addNumber: function (num) {
      dispatch(addAction(num))
    },
    changeBanners(banners) {
      dispatch(changeBannersAction(banners))
    },
    changeRecommend(recommends) {
      dispatch(changeRecommendsAction(recommends))
    },
  }
};;

export default connect(mapStateToProps,mapDispachToProp)(Home)
